#ifndef _MAINWINDOW_H
# define _MAINWINDOW_H

# include "ui_mainwindow.h"
# include "maker_binocular.h"
# include <qt4/Qt/qtimer.h>
# include <qt4/QtCore/QObject>
# include <qt4/QtGui/QWidget>
# include <qt4/QtGui/QMainWindow>
# include <opencv2/opencv.hpp>
#include <boost/iterator/iterator_concepts.hpp>

class mainwindow: public QMainWindow, private Ui::MainWindow
{
    Q_OBJECT
public:
    explicit mainwindow(QWidget* parent = 0);

    void refreshqwtplot();

private slots:
    void read_data();
    void readbtntoggled();
    void stopbtntoggled();
    void update_ui();
    
    void add_new_imu_sample(float acc[3],  float gyro[3]);
    
    void calibrate_acc();
    
    bool checksampleddata();
    
    void calibrateimu();

private:
    QTimer * _readtimer;
    QTimer * _displaytimer;
    
    //程序的状态
    bool _readbtnpushed;
    bool _sensorcalibrated;
    makerbinocular * makerbinocular_;
    double* _sensordata;
    int _qwtdatanumber;
    int _sensorframegot;
    int last_update_index;
    
    double* x_gyro;
    double* y_gyro;
    double* z_gyro;
    double* x_acc;
    double* y_acc;
    double* z_acc;
    int index;
    bool sampled_plane[6];
    
    cv::Mat left_image_;
    cv::Mat right_image_;

    QPolygonF gyro_x_axis, gyro_y_axis, gyro_z_axis;
    QPolygonF acc_x_axis, acc_y_axis, acc_z_axis;
    
    float* acc;
    float* gyro;
    
    int imu_frame_get;
    bool sampling;
    bool calibrated;
    
    // store the imu sample mean data
    double acc_sample[3][6];
    // store the imu sample mean data
    double** gyro_sample;
    
    int plane_index;
    
    // imu标定参数
    double k_a[3][3];
    double b_a[3]; 
};
#endif